package org.sirmupadbapi.persistencia;

import org.sirmupadbapi.beans.Subgruporegimen;
import java.sql.Date; 
import org.sirmupadbapi.beans.*;
import org.sirmupadbapi.controller.*;
import java.io.Serializable;
import java.util.List;
import java.util.ArrayList;
import java.util.*;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import java.util.Map;
import java.util.Iterator;
import java.util.HashMap;
import java.util.Map;
 import javax.sql.DataSource;
import org.sirmupadbapi.generales.Mensajeria;
import org.sirmupadbapi.generales.DataGManager;


/**
*
* @author
*/

public class SubgruporegimenPersistencia implements Serializable {
private static final long serialVersionUID = 1L;
public static Exception excepcion;
public static boolean esMensaje = false;
public static Connection con = null;
public static java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/sirmupadbapi/properties/mensajes");
static DataGManager dataGManager;
static List<Subgruporegimen> list;

public SubgruporegimenPersistencia(){
         esMensaje =false;
}


/**
*
* insert()
*/

public static boolean insert (Subgruporegimen subgruporegimen ) {
  excepcion = null;
  try {
      esMensaje =false;
   
   
   

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pinsert = null;
      String sql = "insert into subgruporegimen(IDSUBGRUPOREGIMEN,IDGRUPOREGIMEN,SUBGRUPO,OBSERVACION,IDUSUARIO,FECHAHORA,idmunicipio,activo)  values(?,?,?,?,?,?,?,?)";
      pinsert = con.prepareStatement(sql);
              pinsert.setString(1,subgruporegimen.getIDSUBGRUPOREGIMEN());
        pinsert.setString(2,subgruporegimen.getIDGRUPOREGIMEN());
        pinsert.setString(3,subgruporegimen.getSUBGRUPO());
        pinsert.setString(4,subgruporegimen.getOBSERVACION());
        pinsert.setString(5,subgruporegimen.getIDUSUARIO());
        pinsert.setDate(6,subgruporegimen.getFECHAHORA());
        pinsert.setString(7,subgruporegimen.getIdmunicipio());
        pinsert.setString(8,subgruporegimen.getActivo());
      int filas= pinsert.executeUpdate();
      pinsert.close();
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
 }


/**
*
* update()
*/

public static boolean update(Subgruporegimen subgruporegimen ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update subgruporegimen set  IDSUBGRUPOREGIMEN=?, IDGRUPOREGIMEN=?, SUBGRUPO=?, OBSERVACION=?, IDUSUARIO=?, FECHAHORA=?, idmunicipio=?, activo=?  where  IDSUBGRUPOREGIMEN ='"+subgruporegimen.getIDSUBGRUPOREGIMEN()+"' and  idmunicipio ='"+subgruporegimen.getIdmunicipio()+"'  ";
      pupdate= con.prepareStatement(sql);
      pupdate.setString(1,subgruporegimen.getIDSUBGRUPOREGIMEN());
pupdate.setString(2,subgruporegimen.getIDGRUPOREGIMEN());
pupdate.setString(3,subgruporegimen.getSUBGRUPO());
pupdate.setString(4,subgruporegimen.getOBSERVACION());
pupdate.setString(5,subgruporegimen.getIDUSUARIO());
pupdate.setDate(6,subgruporegimen.getFECHAHORA());
pupdate.setString(7,subgruporegimen.getIdmunicipio());
pupdate.setString(8,subgruporegimen.getActivo());
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* update()
*/

public static boolean update(String sqlupdate ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update  subgruporegimen set " + sqlupdate +"";
      pupdate= con.prepareStatement(sql);
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* updatePrimaryKey()
*/

public static boolean updatePrimaryKey(Subgruporegimen subgruporegimen_old , Subgruporegimen subgruporegimen) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pupdate = null;
      String sql = "update subgruporegimen set  IDSUBGRUPOREGIMEN=? ,  idmunicipio=?  where  IDSUBGRUPOREGIMEN ='"+subgruporegimen_old.getIDSUBGRUPOREGIMEN()+"' and  idmunicipio ='"+subgruporegimen_old.getIdmunicipio()+"'  ";
      pupdate= con.prepareStatement(sql);
      pupdate.setString(1,subgruporegimen.getIDSUBGRUPOREGIMEN());pupdate.setString(7,subgruporegimen.getIdmunicipio());
      int filas= pupdate.executeUpdate();
      pupdate.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.noupdate"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* delete()
*/

public static boolean delete(Subgruporegimen subgruporegimen ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from subgruporegimen  where  IDSUBGRUPOREGIMEN = ? and  idmunicipio = ?  ";
      pdelete= con.prepareStatement(sql);
      pdelete.setString(1,subgruporegimen.getIDSUBGRUPOREGIMEN());
pdelete.setString(7,subgruporegimen.getIdmunicipio());
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodelete"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* delete()
*/

public static boolean delete(String sqldelete ) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from subgruporegimen where " + sqldelete +"";
      pdelete= con.prepareStatement(sql);
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodelete"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* deleteAll()
*/

public static boolean deleteAll() {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      PreparedStatement pdelete = null;
      String sql = "delete from subgruporegimen  ";
      pdelete= con.prepareStatement(sql);
      int filas= pdelete.executeUpdate();
      pdelete.close();
      if (filas <= 0){
          excepcion=new Exception(bundle.getString("msg.nodeleteall"));
          esMensaje =true;
          return false;
      }
      return true;
   } catch (Exception e) {
      excepcion = e;
   } finally {
  }
  return false;
}


/**
*
* exists()
*/



public static boolean exists(Subgruporegimen subgruporegimen) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return false;
  }
      String sql = "select * from subgruporegimen where IDSUBGRUPOREGIMEN='"+subgruporegimen.getIDSUBGRUPOREGIMEN()+"' and idmunicipio='"+subgruporegimen.getIdmunicipio()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "subgruporegimen" +" " + bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return false;
   }
    rs.close();
    psquery.close();
 return true;
} catch (Exception ex) {
      excepcion = ex;
}
  return false;
}


/**
*
* findByPrimaryKey()
*/



public static Subgruporegimen findByPrimaryKey(Subgruporegimen subgruporegimen) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
      String sql = "select * from subgruporegimen where IDSUBGRUPOREGIMEN='"+subgruporegimen.getIDSUBGRUPOREGIMEN()+"' and idmunicipio='"+subgruporegimen.getIdmunicipio()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "subgruporegimen" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
            
            
            subgruporegimen.setIDSUBGRUPOREGIMEN(rs.getString("IDSUBGRUPOREGIMEN"));
subgruporegimen.setIDGRUPOREGIMEN(rs.getString("IDGRUPOREGIMEN"));
subgruporegimen.setSUBGRUPO(rs.getString("SUBGRUPO"));
subgruporegimen.setOBSERVACION(rs.getString("OBSERVACION"));
subgruporegimen.setIDUSUARIO(rs.getString("IDUSUARIO"));
subgruporegimen.setFECHAHORA(rs.getDate("FECHAHORA"));
subgruporegimen.setIdmunicipio(rs.getString("idmunicipio"));
subgruporegimen.setActivo(rs.getString("activo"));
    }
    rs.close();
    psquery.close();
 return subgruporegimen;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIDSUBGRUPOREGIMEN()
*/

public static List<Subgruporegimen> findByIDSUBGRUPOREGIMEN(Subgruporegimen subgruporegimen,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Subgruporegimen>();
      String sql = "select * from subgruporegimen where IDSUBGRUPOREGIMEN='"+subgruporegimen.getIDSUBGRUPOREGIMEN()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "subgruporegimen" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Subgruporegimen subgruporegimen2 = new Subgruporegimen(
         rs.getString("IDSUBGRUPOREGIMEN"),rs.getString("IDGRUPOREGIMEN"),rs.getString("SUBGRUPO"),rs.getString("OBSERVACION"),rs.getString("IDUSUARIO"),rs.getDate("FECHAHORA"),rs.getString("idmunicipio"),rs.getString("activo"));
            
            
       list.add(subgruporegimen2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIDGRUPOREGIMEN()
*/

public static List<Subgruporegimen> findByIDGRUPOREGIMEN(Subgruporegimen subgruporegimen,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Subgruporegimen>();
      String sql = "select * from subgruporegimen where IDGRUPOREGIMEN='"+subgruporegimen.getIDGRUPOREGIMEN()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "subgruporegimen" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Subgruporegimen subgruporegimen2 = new Subgruporegimen(
         rs.getString("IDSUBGRUPOREGIMEN"),rs.getString("IDGRUPOREGIMEN"),rs.getString("SUBGRUPO"),rs.getString("OBSERVACION"),rs.getString("IDUSUARIO"),rs.getDate("FECHAHORA"),rs.getString("idmunicipio"),rs.getString("activo"));
            
            
       list.add(subgruporegimen2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findBySUBGRUPO()
*/

public static List<Subgruporegimen> findBySUBGRUPO(Subgruporegimen subgruporegimen,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Subgruporegimen>();
      String sql = "select * from subgruporegimen where SUBGRUPO='"+subgruporegimen.getSUBGRUPO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "subgruporegimen" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Subgruporegimen subgruporegimen2 = new Subgruporegimen(
         rs.getString("IDSUBGRUPOREGIMEN"),rs.getString("IDGRUPOREGIMEN"),rs.getString("SUBGRUPO"),rs.getString("OBSERVACION"),rs.getString("IDUSUARIO"),rs.getDate("FECHAHORA"),rs.getString("idmunicipio"),rs.getString("activo"));
            
            
       list.add(subgruporegimen2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByOBSERVACION()
*/

public static List<Subgruporegimen> findByOBSERVACION(Subgruporegimen subgruporegimen,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Subgruporegimen>();
      String sql = "select * from subgruporegimen where OBSERVACION='"+subgruporegimen.getOBSERVACION()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "subgruporegimen" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Subgruporegimen subgruporegimen2 = new Subgruporegimen(
         rs.getString("IDSUBGRUPOREGIMEN"),rs.getString("IDGRUPOREGIMEN"),rs.getString("SUBGRUPO"),rs.getString("OBSERVACION"),rs.getString("IDUSUARIO"),rs.getDate("FECHAHORA"),rs.getString("idmunicipio"),rs.getString("activo"));
            
            
       list.add(subgruporegimen2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIDUSUARIO()
*/

public static List<Subgruporegimen> findByIDUSUARIO(Subgruporegimen subgruporegimen,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Subgruporegimen>();
      String sql = "select * from subgruporegimen where IDUSUARIO='"+subgruporegimen.getIDUSUARIO()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "subgruporegimen" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Subgruporegimen subgruporegimen2 = new Subgruporegimen(
         rs.getString("IDSUBGRUPOREGIMEN"),rs.getString("IDGRUPOREGIMEN"),rs.getString("SUBGRUPO"),rs.getString("OBSERVACION"),rs.getString("IDUSUARIO"),rs.getDate("FECHAHORA"),rs.getString("idmunicipio"),rs.getString("activo"));
            
            
       list.add(subgruporegimen2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByFECHAHORA()
*/

public static List<Subgruporegimen> findByFECHAHORA(Subgruporegimen subgruporegimen,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Subgruporegimen>();
      String sql = "select * from subgruporegimen where FECHAHORA='"+subgruporegimen.getFECHAHORA()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "subgruporegimen" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Subgruporegimen subgruporegimen2 = new Subgruporegimen(
         rs.getString("IDSUBGRUPOREGIMEN"),rs.getString("IDGRUPOREGIMEN"),rs.getString("SUBGRUPO"),rs.getString("OBSERVACION"),rs.getString("IDUSUARIO"),rs.getDate("FECHAHORA"),rs.getString("idmunicipio"),rs.getString("activo"));
            
            
       list.add(subgruporegimen2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByIdmunicipio()
*/

public static List<Subgruporegimen> findByIdmunicipio(Subgruporegimen subgruporegimen,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Subgruporegimen>();
      String sql = "select * from subgruporegimen where idmunicipio='"+subgruporegimen.getIdmunicipio()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "subgruporegimen" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Subgruporegimen subgruporegimen2 = new Subgruporegimen(
         rs.getString("IDSUBGRUPOREGIMEN"),rs.getString("IDGRUPOREGIMEN"),rs.getString("SUBGRUPO"),rs.getString("OBSERVACION"),rs.getString("IDUSUARIO"),rs.getDate("FECHAHORA"),rs.getString("idmunicipio"),rs.getString("activo"));
            
            
       list.add(subgruporegimen2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* findByActivo()
*/

public static List<Subgruporegimen> findByActivo(Subgruporegimen subgruporegimen,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Subgruporegimen>();
      String sql = "select * from subgruporegimen where activo='"+subgruporegimen.getActivo()+"'";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "subgruporegimen" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Subgruporegimen subgruporegimen2 = new Subgruporegimen(
         rs.getString("IDSUBGRUPOREGIMEN"),rs.getString("IDGRUPOREGIMEN"),rs.getString("SUBGRUPO"),rs.getString("OBSERVACION"),rs.getString("IDUSUARIO"),rs.getDate("FECHAHORA"),rs.getString("idmunicipio"),rs.getString("activo"));
            
            
       list.add(subgruporegimen2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* locateByParameters()
*/

public static List<Subgruporegimen> locateByParameters(Map parametros,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
       list = new ArrayList<Subgruporegimen>();
  String sql = "select * from subgruporegimen";
  if (parametros != null) {
      Iterator it = parametros.entrySet().iterator();
      StringBuilder sb = new StringBuilder("");
      int i = 0;
      while (it.hasNext()) {
          if (i != 0){
            sb.append(" and ");
         }
         i++;
        Map.Entry e = (Map.Entry) it.next();
        sb.append(e.getKey() +"= '"+  e.getValue()+"'");
      }
      if (!sb.toString().equals("")){
         sql = sql + " where " + sb.toString();
      }
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "subgruporegimen" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Subgruporegimen subgruporegimen2 = new Subgruporegimen(
         rs.getString("IDSUBGRUPOREGIMEN"),rs.getString("IDGRUPOREGIMEN"),rs.getString("SUBGRUPO"),rs.getString("OBSERVACION"),rs.getString("IDUSUARIO"),rs.getDate("FECHAHORA"),rs.getString("idmunicipio"),rs.getString("activo"));
            
            
       list.add(subgruporegimen2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* Double fFunc(String funcion, String campo)
*/



public static Double func(String funcion, String campo) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0.0;
  }
      String sql = "select "+funcion+"("+campo+") as contador from subgruporegimen";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "subgruporegimen" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0.0;
   }
    Double tmp =0.0;
   rs.beforeFirst();
   while (rs.next()) {
    tmp =  rs.getDouble("contador");
    }
    rs.close();
    psquery.close();
 return tmp;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0.0;
}


/**
*
* Double func(String funcion, String campo,String where)
*/



public static Double func(String funcion, String campo, String where) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0.0;
  }
      String sql = "select "+funcion+"("+campo+") as contador from subgruporegimen where "+where +" ";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "subgruporegimen" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0.0;
   }
    Double tmp =0.0;
   rs.beforeFirst();
   while (rs.next()) {
    tmp =  rs.getDouble("contador");
    }
    rs.close();
    psquery.close();
 return tmp;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0.0;
}


/**
*
* count()
*/



public static Integer count() {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0;
  }
      String sql = "select count(*) as contador from subgruporegimen";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "subgruporegimen" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0;
   }
   rs.beforeFirst();
   while (rs.next()) {
    x =  rs.getInt("contador");
    }
    rs.close();
    psquery.close();
 return x;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0;
}


/**
*
* count(String sqlquery)
*/



public static Integer count(String sqlquery) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return 0;
  }
      String sql = "select count(*) as contador from subgruporegimen where  " + sqlquery +"";
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "subgruporegimen" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return 0;
   }
   rs.beforeFirst();
   while (rs.next()) {
    x =  rs.getInt("contador");
    }
    rs.close();
    psquery.close();
 return x;
} catch (Exception ex) {
      excepcion = ex;
}
  return 0;
}


/**
*
* query()
*/

public static List<Subgruporegimen> query(String query,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
        list = new ArrayList<Subgruporegimen>();
  String sql = "select * from subgruporegimen where " + query +"";
  if (query == null || query.equals("")) {
  return null;
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "subgruporegimen" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
   
        Subgruporegimen subgruporegimen2 = new Subgruporegimen(
         rs.getString("IDSUBGRUPOREGIMEN"),rs.getString("IDGRUPOREGIMEN"),rs.getString("SUBGRUPO"),rs.getString("OBSERVACION"),rs.getString("IDUSUARIO"),rs.getDate("FECHAHORA"),rs.getString("idmunicipio"),rs.getString("activo"));
            
            
       list.add(subgruporegimen2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
}


/**
*
* getListRecords()
*/

public static List<Subgruporegimen> getListRecords(Map parametros,boolean withRelation) {
  excepcion = null;
  try {
      esMensaje =false;

  con= dataGManager.getCon();
  if (con == null) {
      excepcion=new Exception(bundle.getString("msg.noconecction"));
      return null;
  }
      list = new ArrayList<Subgruporegimen>();
  String sql = "select * from subgruporegimen";
  if (parametros != null) {
      Iterator it = parametros.entrySet().iterator();
      StringBuilder sb = new StringBuilder("");
      while (it.hasNext()) {
        Map.Entry e = (Map.Entry) it.next();
        sb.append(e.getKey() +"="+  e.getValue());
      }
      if (!sb.toString().equals("")){
         sql = sql + " where " + sb.toString();
      }
   }
  PreparedStatement psquery = con.prepareStatement(sql,ResultSet.TYPE_SCROLL_INSENSITIVE,
                                      ResultSet.CONCUR_UPDATABLE);
   ResultSet rs = psquery.executeQuery();
   rs.next();
   int x = rs.getRow();
   if (x == 0) {
          excepcion=new Exception(bundle.getString("msg.nofoundrecords") + "subgruporegimen" +"  "+ bundle.getString("msg.withcode"));
          esMensaje =true;
      rs.close();
      psquery.close();
      return null;
   }
   rs.beforeFirst();
   while (rs.next()) {
       
        Subgruporegimen subgruporegimen2 = new Subgruporegimen(
         rs.getString("IDSUBGRUPOREGIMEN"),rs.getString("IDGRUPOREGIMEN"),rs.getString("SUBGRUPO"),rs.getString("OBSERVACION"),rs.getString("IDUSUARIO"),rs.getDate("FECHAHORA"),rs.getString("idmunicipio"),rs.getString("activo"));
            
            
       list.add(subgruporegimen2);
    }
    rs.close();
    psquery.close();
    return list;
} catch (Exception ex) {
      excepcion = ex;
}
  return null;
 }


}
